const defaultState = {
  inputValue:'',
  list:[
    'Racing car sprays burning fuel into crowd.',
    'Japanese princess to wed commoner.',
    'Australian walks 100km after outback crash.',
    'Man charged over missing wedding girl.',
    'Los Angeles battles huge wildfires.',
  ]
}

export default (state = defaultState,action)=>{
  if (action.type ==='change_input_value'){
    return Object.assign({}, state, {
      inputValue: action.value
    })
  }

  if (action.type === 'add_list'){
    return Object.assign({}, state, {
      list: action.value,
      inputValue:''
    })
  }

  if (action.type === 'delete_item') {
    let list = JSON.parse(JSON.stringify(state.list));
    list.splice(action.value, 1)
    return Object.assign({}, state, {
      list: list,
      inputValue: ''
    })
  }

  return state;
}